
const mongoose = require('mongoose');
let hostname = '0.0.0.0';
let port = 27017;
let dbname= 'express';


const db_conn = `mongodb://${hostname}:${port}/${dbname}`;

mongoose.connect(db_conn,{
    useNewUrlParser:true,
    useUnifiedTopology:true
},(err)=>{
    if(err){
        console.log("数据库链接失败---"+err)
    }else{
        console.log("数据库链接成功---successful")
    }
})

var connection = mongoose.connection;

connection.on("connected",()=>{
    console.log("数据库已经链接 --- connected")
})

connection.on("error",(err)=>{
    console.log("数据库链接异常 --- "+err);
})

connection.on("disconnected",()=>{
    console.log("数据库断开链接 --- disconnected")
})